﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Scan.PDAService;
using Scan.Controls;

namespace Scan
{
    public partial class ReferCompanyView : BaseView
    {
        // 客商数据
        //private Company[] gCompanys = null;
        //public Company[] Companys
        //{
        //    get { return gCompanys; }
        //    set { gCompanys = value; }
        //}

        public ReferCompanyView()
        {
            InitializeComponent();
            this.Title = "客商选择";

            // 往ListView添加可以排序的列
            this.SuspendLayout();
            this.ResumeLayout(false);
        }

        public override void OnLoad()
        {
            if (needClearView)
            {
                needClearView = false;
                lstData.Items.Clear();
                txtCode.Text = "";
                txtName.Text = "";
            }

            lstData.Focus();
            if (lstData.Items.Count > 0)
            {
                lstData.Items[0].Selected = true;
            }
        }

        protected override void FocusControl(bool forward)
        {

        }

        //// 绑定表格数据
        //public void DataBind(Company[] Companys)
        //{
        //    lstData.Items.Clear();
        //    if (Companys != null && Companys.Length != 0)
        //    {
        //        foreach (Company Company in Companys)
        //        {
        //         //   ListViewItem item = new ListViewItem(new string[] { Company.CompCode, Company.CompName, Company.LinkMan, Company.Phone, Company.Address });
        //          //  lstData.Items.Add(item);
        //        }
        //    }
        //    else
        //    {
        //        MessageBox.Show("没有获取到数据！", this.Title);
        //    }
        //}

        // 查找供应商
        public void Find(string CompanyCode, string CompanyName)
        {
            //gCompanys = ArchivesCompanys.GetCompanys(true, 2, CompanyCode, CompanyName);
            //DataBind(gCompanys);
        }

        // 返回
        public override void Escape(object sender, EventArgs e)
        {
            this.ParentForm.LoadView(this.ResultView.GetType(), null, true, false);
        }

        // 确定，S2键
        public override void S2(object sender, EventArgs e)
        {
            int SelectIndex = 0;
            for (int i = 0; i < lstData.Items.Count; i++)
            {
                if (lstData.Items[i].Selected)
                {
                    SelectIndex = i;
                    break;
                }
            }
            //this.ResultView.ReturnProc(true, ReferType.Company, gCompanys[SelectIndex]);
            this.ParentForm.LoadView(this.ResultView.GetType(), null, true, false);
        }

        // 定位、过滤编码和名称
        private void txtName_TextChanged(object sender, EventArgs e)
        {
            /*
            ListViewItem foundItem = lstData.FocusedItem .FindItemWithText(textBox1.Text,false,0,true); 
            if (foundItem!=null) 
            {
                lstData.TopItem = foundItem;
                lstData.FindItemWithText(textBox1.Text, false, 0, true).BackColor = Color.Beige; 
            }
             * */
        }

        private void txtCode_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
